package cn.chiship.framework.upms.core.runner;

import cn.chiship.framework.common.constants.CommonCacheConstants;
import cn.chiship.framework.upms.biz.base.service.CacheService;
import cn.chiship.sdk.cache.service.RedisService;
import cn.chiship.sdk.cache.service.UserCacheService;
import cn.chiship.sdk.core.base.constants.CacheConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 初始化数据
 *
 * @author lijian
 */
@Component
@Order(1)
public class UpmsDataRunner implements CommandLineRunner {
    private static final Logger LOGGER = LoggerFactory.getLogger(UpmsDataRunner.class);
    @Resource
    RedisService redisService;
    @Resource
    UserCacheService userCacheService;
    @Resource
    CacheService cacheService;

    @Override
    public void run(String... args) throws Exception {
        LOGGER.info("----------------UpmsRunner---------------------");

        /**
         * 在线用户下线
         */
        redisService.removeAll(CommonCacheConstants.buildKey(CacheConstants.REDIS_ONLINE_USER_PREFIX));
        redisService.removeAll(CommonCacheConstants.buildKey(CommonCacheConstants.REDIS_QRCODE_LOGIN_PREFIX));

        cacheService.cacheConfigs();
        LOGGER.info("缓存系统配置数据结束！");

        cacheService.cacheProofs();
        LOGGER.info("缓存密钥数据结束！");

        cacheService.cacheDataDict();
        LOGGER.info("缓存数据字典数据结束！");

        cacheService.cacheEmailSettingConfig();
        LOGGER.info("缓存邮箱配置数据结束！");

        cacheService.cacheSystems();
        LOGGER.info("缓存系统数据结束！");

        cacheService.cachePosts();
        LOGGER.info("缓存岗位数据结束");

        cacheService.initQuartzJob();
        LOGGER.info("启动所有任务！");

        cacheService.cacheApp();
        LOGGER.info("缓存最新APP结束");

    }
}
